// order_pkg/pages/order/order.js
Page({
  data: {
    dataType: 'all',
    orderList: []
  },
  onLoad(query) {
    this.setData({dataType: query.dataType})
  },
  onShow() {
    this.getOrderList()
  },
  // 获取订单列表
  async getOrderList() {
    const res = await wx.http.get('/order/list', {
      dataType: this.data.dataType,
      page: 1
    })
    const orderList = res.data.data.list.data
    this.setData({orderList})
  },
  // 点击tab栏切换评价类型
  onTabsClick(ev) {
    this.setData({
      dataType: ev.detail.value
    })
    this.getOrderList()
  },
  // 前往订单详情
  toOrderDetail(ev) {
    const orderId = ev.mark.orderId
    wx.navigateTo({
      url: `../orderdetail/orderdetail?orderId=${orderId}`,
    })
  },
  // 取消订单
  async orderCancel(ev) {
    const orderId = ev.mark.orderId
    const res = await wx.http.post('/order/cancel', {orderId})
    if(res.data.status === 200) {
      wx.showToast({
        title: '取消成功'
      })
    }
  }
})